<template>
  <div class="wrapper">
    <p class="iconP pointer" @click="noticeDetail(notices[0].id)"><i class="icon-broadcast"></i>【{{$t('pageTitle.notice_info')}}】</p>
    <swiper :options="swiperOption" v-if="showNotices" ref="mySwiper">
      <swiper-slide v-for="(item, index) of notices" :key="index">
        <p class="titles" @click="noticeDetail(item.id)">{{item.title}}</p>
      </swiper-slide>
    </swiper>
    <div class="MoreNotices" @click="noticeDetail(notices[0].id)">{{$t('main.more')}}</div>
  </div>
</template>

<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
  name: 'notices',
  props: {
    notices: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true,
        autoplay: 5000,
        direction: 'vertical',
        observer: true,
        observeParents: true
      }
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  computed: {
    showNotices () {
      return this.notices.length
    }
  },
  methods: {
    noticeDetail (i) {
      localStorage.setItem('ntId', i)
      this.$router.push({name: 'notice_info', query: { ntId: i }})
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper{
  position: relative;
  width: 340px;
  height: 40px;
  overflow: inherit;
  .iconP{
    position: absolute;
    left: -78px;
    top: 0;
    vertical-align: top;
    width: 80px;
    font-size: 16px;
    i{
      margin-right: 6px;
      color: #ee6560 ;
    }
  }
  .swiper-container{
    width: 100%;
    height: 100%;
    .swiper-slide{
      p.titles{
        max-width: 340px;
        line-height: 40px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }
    }
  }
  .MoreNotices{
    position: absolute;
    right: -40px;
    top: 0;
    cursor: pointer;
  }
}
</style>
